<?php
class Getnew_model extends CI_Model
{
	
	public function __construct()
	{
		$this->load->database();
		$this->load->library('session');
	}
	public function getUserId()
	{
	    $sql = 	'SELECT auto_id FROM '.CI_Model::$newUser.' WHERE wechat_id = ?;';
	    $result = $this->db->query($sql,array($_SESSION['wechat']))->row_array();
	    if(isset($result))
	    {
	    	return $result['auto_id'];
	    }
	    else
	    {
	    	$this->insertIDViaWechat()['auto_id'];
	    }
	}

	public function insertIDViaWechat()
	{
		$sql = 'CALL insertAndGetID(?);';
		return $this->db->query($sql,array($_SESSION['wechat']))->row_array();
	}
}